<script>
	import { appInit } from './utils/appInit.js'
	import { checkBeforeNavigate } from './utils/loginCheck.js'
	
	export default {
		onLaunch: function() {
			console.log('App Launch')
			// 应用初始化
			appInit()
			
			// 全局路由守卫
			this.setupRouteGuard()
		},
		onShow: function() {
			console.log('App Show')
		},
		onHide: function() {
			console.log('App Hide')
		},
		methods: {
			// 设置路由守卫
			setupRouteGuard() {
				// 保存原始方法
				const originalNavigateTo = uni.navigateTo
				const originalSwitchTab = uni.switchTab
				
				// 重写uni.navigateTo
				uni.navigateTo = function(options) {
					console.log('navigateTo 被调用:', options.url)
					if (checkBeforeNavigate(options.url)) {
						return originalNavigateTo.call(this, options)
					}
				}
				
				// 重写uni.switchTab
				uni.switchTab = function(options) {
					console.log('switchTab 被调用:', options.url)
					if (checkBeforeNavigate(options.url)) {
						return originalSwitchTab.call(this, options)
					}
				}
				
				console.log('路由守卫已设置')
			}
		}
	}
</script>

<style lang="scss">
	/*每个页面公共css */
		/* 注意要写在第一行，同时给style标签加入lang="scss"属性 */
		@import "uview-ui/index.scss";
		
		
		@import "./static/fonts/iconfont.css";
</style>
